package com.itheima.controller;

import com.itheima.pojo.Brand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/brands")
public class BrandController {

    //查询全部 http://localhost/brands
    //查询ID http://localhost/users/1/zs get
    //路径参数 /{param} @PathVariable 参数
    //路径参数 /{param}/{name} @PathVariable 参数,
    @GetMapping("/{id}")
    @ResponseBody
    public Brand findBrand(@PathVariable Integer id){
        Brand brand = new Brand();
        brand.setId(id);
        brand.setId(id);
        brand.setBrandName("黑马");
        brand.setCompanyName("传智");
        return brand;
    }

    //修改 put http://localhost:8081/brands
    @PutMapping
    @ResponseBody
    public String updateBrand(@RequestBody Brand brand){
        System.out.println(brand);
        return "修改成功 OK";
    }

    //增加 http://localhost:8081/brands
    @PostMapping
    @ResponseBody
    public String saveBrand(Brand brand){
        System.out.println(brand);
        return "添加成功 OK";
    }

    //删除 delete http://localhost:8081/brands/1
    @DeleteMapping
    @ResponseBody
    public String deleteBrand(@PathVariable Integer id){
        System.out.println("id="+id);
        return "删除成功 OK";
    }
}
